package cn.johnyu;

import cn.johnyu.handler.HelloHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.net.InetSocketAddress;

public class SimpleHttpServer {
    public static void main(String[] args) throws IOException {
        // 创建 HTTP 服务器，监听 8080 端口
        HttpServer server = HttpServer.create(new InetSocketAddress(3000), 0);
        // 创建一个上下文，将 "/hello" 路径与处理程序关联
        server.createContext("/hello", new HelloHandler());
        // 启动服务器
        server.setExecutor(null); // 默认线程池
        server.start();

        System.out.println("Server is running at http://localhost:3000/hello");
    }
}
